﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QLSVPT1h
{
    public partial class BaoCao : Form
    {
        public BaoCao()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string a = comboBox1.SelectedItem.ToString();
            string b = comboBox2.SelectedItem.ToString();
            string c = comboBox3.SelectedItem.ToString();
            string d = "K" + b[2] + b[3];
            string command = "select tb1.MaLop, tb1.SiSo, tb2.SoLuongDat, (tb2.SoLuongDat * 100 / tb1.SiSo) as TiLe from (select MaLop, MaNH, count(*) as SiSo from HOCSINH group by MaLop, MaNH) as tb1, (select hs.MaLop, hs.MaNH, mh.TenMH, bd.HocKy, count(*) as SoLuongDat from HOCSINH hs join BANGDIEM bd on hs.MaHS = bd.MaHS join MONHOC mh on mh.MaMH = bd.MaMH where bd.DiemTrungBinh >= 5 group by hs.MaLop, hs.MaNH, mh.TenMH, bd.HocKy) as tb2 "
                + "where tb1.MaLop = tb2.MaLop and tb1.MaNH = tb2.MaNH and "
                + "tb2.TenMH = N'" + a + "' and "
                + "tb2.HocKy = " + c + " and "
                + "tb1.MaNH = '" + d + "'";
            con.Open();
            DataTable table = new DataTable();
            SqlDataAdapter data = new SqlDataAdapter(command, con);
            data.Fill(table);
            dataGridView1.DataSource = table;
            con.Close();
        }
        public SqlConnection con;
        private void Form3_Load(object sender, EventArgs e)
        {
            string connection = "Data Source=.;Initial Catalog=QLHS;Integrated Security=True";
            con = new SqlConnection(connection);
        }

        private void BaoCao_FormClosed(object sender, FormClosedEventArgs e)
        {
            Homepage_Form hp = new Homepage_Form();
            this.Visible = false;
            hp.Show();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            Homepage_Form hp = new Homepage_Form();
            this.Visible = false;
            hp.Show();
        }

    }
}
